from redis import Redis
from config import REDIS_IP, REDIS_PORT
r = Redis(host=REDIS_IP, port=REDIS_PORT, db=1, health_check_interval=10,
            socket_timeout=10, socket_keepalive=True,
            socket_connect_timeout=10, retry_on_timeout=True)

class Storage:
    def __init__(self):
        self.r = r

    def sets(self, key, value,expire=None):
        self.r.json().set(key, "$", value)
        if expire:
            r.expire(key, expire)

    def gets(self, key):
        return self.r.json().get(key, "$")

    def delete(self, key):
        return self.r.delete(key)

if __name__ == "__main__":
    st = Storage()
    print(st.gets("111"))